﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CashierSystem.UserManager;

namespace CashierSystem.remindManager
{
    public partial class SearchRemindForm : Form
    {
        User user;
        public SearchRemindForm(User user)
        {
            this.user = user;
            InitializeComponent();
        }

        /* private void dtpStartDate1_ValueChanged(object sender, EventArgs e)
         {
             tbStartDate1.Text = dtpStartDate1.Value.Date.ToString();
         }

         private void dtpEndDate1_ValueChanged(object sender, EventArgs e)
         {
             tbEndDate1.Text = dtpEndDate1.Value.Date.ToString();
         }
       
         private void button9_Click(object sender, EventArgs e)
         {
             string startDate = "";
             if (tbStartDate1.Text != "")
             {
                 startDate = tbStartDate.Text;

             }
             else
             {
                 startDate = "";
             }
             string endDate = "";
             if (tbEndDate1.Text != "")
             {
                 endDate = tbEndDate.Text;
             }
             else
             {
                 endDate = "";
             }
             UserRemindManager.loadAllRemind(listView2, startDate, endDate);

         }
          */
        private void button5_Click(object sender, EventArgs e)
        {
            if (listView2.SelectedItems.Count != 1)
            {
                DialogResult response = MessageBox.Show("请选择一条记录！");
                return;

            }
            else
            {
                DialogResult r = MessageBox.Show("请确认删除一个提醒", "请确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (r == System.Windows.Forms.DialogResult.Yes)
                {
                    string id = listView2.SelectedItems[0].SubItems[0].Text;
                    UserRemindManager.deleteRemind(id);
                    DialogResult response = MessageBox.Show("删除成功！");
                    string startDate = "";
                    if (tbStartDate1.Text != "")
                    {
                        startDate = tbStartDate1.Text;

                    }
                    else
                    {
                        startDate = "";
                    }
                    string endDate = "";
                    if (tbEndDate1.Text != "")
                    {
                        endDate = tbEndDate1.Text;
                    }
                    else
                    {
                        endDate = "";
                    }
                    UserRemindManager.loadAllRemind(listView2, startDate, endDate);

                }
                else
                {
                    return;
                }
            }

        }

        string id;

        /*  private void dtpRemindDate_ValueChanged(object sender, EventArgs e)
          {
              tbRemindDate1.Text = dtpRemindDate1.Value.Date.ToString();
          }
       
          private void button1_Click(object sender, EventArgs e)
          {
              string content = rtbContent1.Text;
              string remindDate = tbRemindDate1.Text;
              UserRemindManager.updateRemind(id, content, remindDate);
              DialogResult response = MessageBox.Show("更新成功！");
              rtbContent1.Text = "";
              tbRemindDate1.Text = "";
              string startDate = "";
              if (tbStartDate1.Text != "")
              {
                  startDate = tbStartDate1.Text;

              }
              else
              {
                  startDate = "";
              }
              string endDate = "";
              if (tbEndDate1.Text != "")
              {
                  endDate = tbEndDate1.Text;
              }
              else
              {
                  endDate = "";
              }
              UserRemindManager.loadAllRemind(listView2, startDate, endDate);

          } */

        private void SearchRemindForm_Load_1(object sender, EventArgs e)
        {
            string startDate = "";
            if (tbStartDate1.Text != "")
            {
                startDate = tbStartDate1.Text;

            }
            else
            {
                startDate = "";
            }
            string endDate = "";
            if (tbEndDate1.Text != "")
            {
                endDate = tbEndDate1.Text;
            }
            else
            {
                endDate = "";
            }
            UserRemindManager.loadAllRemind(listView2, startDate, endDate);
        }

       /* private void listView1_DoubleClick(object sender, EventArgs e)
        {
            id = listView2.SelectedItems[0].SubItems[0].Text;
            rtbContent.Text = listView2.SelectedItems[0].SubItems[1].Text;
            tbRemindDate.Text = listView2.SelectedItems[0].SubItems[2].Text;
        }
        */
        private void listView2_DoubleClick(object sender, EventArgs e)
        {
            id = listView2.SelectedItems[0].SubItems[0].Text;
            rtbContent1.Text = listView2.SelectedItems[0].SubItems[1].Text;
            tbRemindDate1.Text = listView2.SelectedItems[0].SubItems[2].Text;
        }

        private void dtpRemindDate1_ValueChanged(object sender, EventArgs e)
        {
            tbRemindDate1.Text = dtpRemindDate1.Value.Date.ToString();
        }
        
        private void dtpStartDate1_ValueChanged_1(object sender, EventArgs e)
        {
            tbStartDate1.Text = dtpStartDate1.Value.Date.ToString();
        }

        private void dtpEndDate1_ValueChanged_1(object sender, EventArgs e)
        {
            tbEndDate1.Text = dtpEndDate1.Value.Date.ToString();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            string content = rtbContent1.Text;
            string remindDate = tbRemindDate1.Text;
            UserRemindManager.updateRemind(id, content, remindDate);
            DialogResult response = MessageBox.Show("更新成功！");
            rtbContent1.Text = "";
            tbRemindDate1.Text = "";
            string startDate = "";
            if (tbStartDate1.Text != "")
            {
                startDate = tbStartDate1.Text;

            }
            else
            {
                startDate = "";
            }
            string endDate = "";
            if (tbEndDate1.Text != "")
            {
                endDate = tbEndDate1.Text;
            }
            else
            {
                endDate = "";
            }
            UserRemindManager.loadAllRemind(listView2, startDate, endDate);

        }

        private void button4_Click(object sender, EventArgs e)
        {
            string startDate = "";
            if (tbStartDate1.Text != "")
            {
                startDate = tbStartDate1.Text;

            }
            else
            {
                startDate = "";
            }
            string endDate = "";
            if (tbEndDate1.Text != "")
            {
                endDate = tbEndDate1.Text;
            }
            else
            {
                endDate = "";
            }
            UserRemindManager.loadAllRemind(listView2, startDate, endDate);
        }




    }
}